package com.magenta.maxoptra.gis;

import com.magenta.maxoptra.dto.GeoLocationRecord;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 * User: KuznetsovD
 * Date: 01.10.13
 * Time: 18:24
 * To change this template use File | Settings | File Templates.
 */
public interface SyncGeoroutingServiceRemote extends ISyncGeoRoutingService {

    public static final String JNDI_NAME = "SyncGeoroutingServiceRemote";


    GeoRoute getFastestRoute(@Nullable UUID userId, GeoProviderSettings settings, GeographicCoordinates from, GeographicCoordinates to);

    List<GeoLocationRecord> getRoutePoints(@Nullable UUID userId, GeoProviderSettings settings, GeographicCoordinates from,
                                           GeographicCoordinates to, boolean calculateDistance) throws GeoException;

    GeoProviderStatus updateCache(@Nullable UUID userId, GeoProviderSettings settings, RoutingCoordinate from, RoutingCoordinate to, int delayBeforeRequests);

    /**
     * Bath updating for routes from origin to destination
     *
     * @param settings            geo provider settings
     * @param origin              starting point of the routes
     * @param destinations        list of final destinations
     * @param delayBeforeRequests time that you need to wait before using the provider
     * @return current status of provider
     */
    GeoProviderStatus updateCache(@Nullable UUID userId, GeoProviderSettings settings, GeographicCoordinates origin,
                                  List<? extends GeographicCoordinates> destinations, int delayBeforeRequests);

    GeoRoute getRoute(@Nullable UUID userId, GeoProviderSettings settings, List<GeographicCoordinates> coordinates) throws GeoException;

    List<GeoLocationRecord> getRoutePoints(@Nullable UUID userId, GeoProviderSettings settings, List<GeographicCoordinates> points) throws GeoException;

    /**
     * Bath updating for routes between points
     *
     * @param from                starting point of the routes
     * @param settings            geo provider settings
     * @param points              points of the routes
     */
    void updateCache(@Nullable UUID userId, GeoProviderSettings settings, RoutingCoordinate from, List<RoutingCoordinate> points);

    /**
     * Batch updating for routes between points (w/o reverse routes)
     */
    void updateCache(@Nullable UUID userId, GeoProviderSettings settings, List<RoutingCoordinate> from, List<RoutingCoordinate> to);

    /**
     * Clean expired cache and return date of first oldest entry
     *
     * @param maxAge milliseconds
     * @return date of first oldest entry
     */
    long cleanAndGetDateOfFirstOldest(@Nullable UUID userId, long cid, long maxAge);

    /**
     * Getting distance and trip duration going through all points in order in which they are listed
     *
     * @param settings    geo provider settings
     * @param coordinates list of stops
     * @return calculated distance and duration
     */
    @Nullable
    List<GeoRoute> getCoordinateToCoordinateRoutes(@Nullable UUID userId, GeoProviderSettings settings, List<GeographicCoordinates> coordinates);

}
